package com.fmjr.web.handler;

import com.fmjr.common.base.exception.BusinessException;
import com.fmjr.web.base.BaseController;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author lun.li@163.com
 */
@RestControllerAdvice
public class BizExceptionHandler extends BaseController {

	@ExceptionHandler({ BusinessException.class })
	@ResponseStatus(HttpStatus.OK)
	public String processBizException(BusinessException e) {
		logger.error(e.toString());
		return error(e.getMessage());
	}
	@ExceptionHandler({ UnauthorizedException.class })
	@ResponseStatus(HttpStatus.OK)
	public String processBizException(UnauthorizedException e) {
		logger.error(e.toString());
		return error("没有权限");
	}
	
	@ExceptionHandler({ Exception.class })
	@ResponseStatus(HttpStatus.OK)
	public String processException(Exception e) {
		e.printStackTrace();
		logger.error(e.getMessage(), e);
		return error("系统错误");
	}

}
